Quadratic Residues
Introduction
- In ordinary arithmetic, a perfect square is any number of the form $x^2$ for an integer $x$.
Examples: $0,1,4,9,16,25,\dots$ - In modular arithmetic, we ask a similar but more subtle question:
Which numbers behave like perfect squares once we reduce everything modulo $n$? - A number $a$ is called a quadratic residue modulo $n$ if there exists an integer $x$ such that $$x^2 \equiv a \pmod{n}.$$
- If no such $x$ exists, then $a$ is a quadratic non‑residue.
- For example, $6$ is a square mod $10$ (since $4^2 \equiv 6$), but $3$ is not
Why this matters
- Squaring is easy; “unsquaring” (finding square roots) is often hard.
- Patterns of quadratic residues reveal deep structure in modular arithmetic.
- These ideas appear in:
- primality testing
- cryptography
- pseudorandom number generation
- classical number theory
Perfect Squares in the Integers
- A quick warm‑up:
- Squares grow quickly: $0,1,4,9,16,25,\dots$
- Differences between squares: $1,3,5,7,\dots$ (always odd)
- Useful facts:
- Squares are never negative.
- Squares mod $n$ “wrap around,” so many more numbers can appear as residues.
Squares Modulo $n$: First Examples
Modulo $7$
Compute $x^2 \bmod 7$ for $x=0$ to $6$:
- $0^2 \equiv 0$
- $1^2 \equiv 1$
- $2^2 \equiv 4$
- $3^2 \equiv 2$
- $4^2 \equiv 2$
- $5^2 \equiv 4$
- $6^2 \equiv 1$
Quadratic residues mod $7$: $\{0,1,2,4\}$
Modulo $10$
- $0^2 \equiv 0$
- $1^2 \equiv 1$
- $2^2 \equiv 4$
- $3^2 \equiv 9$
- $4^2 \equiv 6$
- $5^2 \equiv 5$
- $6^2 \equiv 6$
- $7^2 \equiv 9$
- $8^2 \equiv 4$
- $9^2 \equiv 1$
Quadratic residues mod $10$: $\{0,1,4,5,6,9\}$
Defining Quadratic Residues and Non‑Residues
- A number $a$ is a quadratic residue mod $n$ if $$x^2 \equiv a \pmod{n}$$ has a solution.
- If no such $x$ exists, $a$ is a quadratic non‑residue.
- Examples:
- $2$ is a residue mod $7$ (since $3^2 \equiv 2$).
- $3$ is a non‑residue mod $7$.
Patterns of Squares Modulo a Prime
When $p$ is prime:
- There are exactly $\frac{p-1}{2}$ nonzero quadratic residues.
- Squaring “folds” the multiplicative group in half.
- Example mod $11$:
- Squares: $1,3,4,5,9$
- Non‑residues: $2,6,7,8,10$
Patterns:
- Residues come in pairs: $$x^2 \equiv (-x)^2 \pmod{p}$$
- Roughly half the numbers are residues, half are not.
Why Some Numbers Are Never Squares Modulo $n$
Reasons include:
- Parity issues:
- Mod $8$, every odd square is $\equiv 1 \pmod{8}$.
- Prime factorization:
- If $n$ has prime factors, a number must be a residue modulo each prime power.
- Group structure:
- In $(\mathbb{Z}/p\mathbb{Z})^\times$, squaring is a 2‑to‑1 map.
Example:
- Mod $8$, the only odd quadratic residue is $1$.
The Structure of the Multiplicative Group Mod $p$
For prime $p$:
- The nonzero numbers mod $p$ form a group under multiplication.
- This group is cyclic:
- There exists a generator $g$ such that every nonzero number is $g^k$.
- Squares correspond to even exponents: $$g^{2k}$$
- This explains why exactly half the nonzero elements are squares.
The Legendre Symbol: A Compact Notation
The Legendre symbol is a shorthand for “is $a$ a square mod $p$?”: $$\left( \frac{a}{p} \right) = \begin{cases} \;\;1 & \text{if $a$ is a quadratic residue mod $p$ and } a\not\equiv 0 \\ -1 & \text{if $a$ is a non‑residue mod $p$} \\ \;\;0 & \text{if } p \mid a \end{cases}$$ Examples:
- $\left(\frac{2}{7}\right)=1$
- $\left(\frac{3}{7}\right)=-1$
- $\left(\frac{14}{7}\right)=0$
Basic Properties of the Legendre Symbol
Useful rules:
- Multiplicativity: $$\left(\frac{ab}{p}\right)=\left(\frac{a}{p}\right)\left(\frac{b}{p}\right)$$
- Squares are always residues: $$\left(\frac{x^2}{p}\right)=1$$
- Reduction:
- Only the value of $a \bmod p$ matters.
These rules make computations much easier.
Euler’s Criterion
A powerful test for residues: $$\left(\frac{a}{p}\right) \equiv a^{\frac{p-1}{2}} \pmod{p}$$
Interpretation:
- If $a^{(p-1)/2} \equiv 1$, then $a$ is a residue.
- If $a^{(p-1)/2} \equiv -1$, then $a$ is a non‑residue.
Example mod $11$:
- $2^{5} = 32 \equiv -1 \pmod{11}$
So $2$ is a non‑residue.
Quadratic Reciprocity: A First Glimpse
One of the most beautiful results in number theory:
For odd primes $p$ and $q$: $$\left(\frac{p}{q}\right)\left(\frac{q}{p}\right)= (-1)^{\frac{(p-1)(q-1)}{4}}$$ Meaning:
- If both primes are $\equiv 1 \pmod{4}$, residues “match.”
- If both are $\equiv 3 \pmod{4}$, residues “flip.”
Solving Quadratic Congruences
Goal: solve $$x^2 \equiv a \pmod{p}$$ Basic strategies:
- Trial and error for small $p$.
- Use Legendre symbol to check if solutions exist.
- Use structure of the group:
- If $a = g^k$ and $x = g^m$, then $$2m \equiv k \pmod{p-1}$$
- Tonelli–Shanks algorithm (optional for advanced readers).
Example:
- Solve $x^2 \equiv 4 \pmod{11}$
- $x \equiv \pm 2 \pmod{11}$
Applications in Cryptography and Pseudorandomness
Quadratic residues appear in:
- Quadratic residue generators (pseudorandom number generators)
- Goldwasser–Micali encryption
- Zero‑knowledge proofs
- Hash functions based on modular squaring
Key idea:
- It is easy to compute $x^2 \bmod n$
- It is often hard to determine whether a number is a square mod $n$ when $n$ is composite.
Common Pitfalls and Misconceptions
- “Half the numbers are residues mod any $n$.”
- False: only true for primes.
- “If $a$ is a residue mod $p$, then it’s a residue mod $p^k$.”
- “Residues behave randomly.”
- They follow deep algebraic patterns.
Summary
- Quadratic residues generalize the idea of perfect squares to modular arithmetic.
- Modulo a prime:
- Exactly half the nonzero numbers are residues.
- The Legendre symbol provides a compact notation.
- Euler’s criterion gives a fast test.
- Quadratic reciprocity links residues across different primes.
- These ideas have real applications in modern cryptography.
Calculator
Legendre
- Checks if a number is a quadratic residue
legendre(2, 7) legendre(3, 7) legendre(14, 7)
List quadratic residues
- Lists all quadratic residues
listQuadraticResidues(9) listQuadraticResidues(10)
Exercises
Try to solve these without a calculator when possible.
- Compute all quadratic residues modulo $9$.
- Determine whether $5$ is a quadratic residue modulo $11$.
- Find all solutions to $x^2 \equiv 6 \pmod{10}$.
- Compute $\left(\frac{3}{7}\right)$ using Euler’s criterion.
- List all quadratic residues modulo $13$.
- Show that every odd square is $\equiv 1 \pmod{8}$.
- Solve $x^2 \equiv 4 \pmod{17}$.
- Determine whether $10$ is a quadratic residue modulo $19$.
- Prove or disprove: “If $a$ is a quadratic residue mod $p$, then $-a$ is also a residue mod $p$.”
- Challenge: Use quadratic reciprocity to determine whether $7$ is a quadratic residue modulo $23$.